# -*- coding: utf-8 -*-
#import editarea
from datetime import datetime
from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
from django.forms import Form, ModelChoiceField, IntegerField, Textarea, CharField, HiddenInput

# Create your models here.

class Problem(models.Model):
    title = models.CharField('Название', max_length = 200)
    statement = models.TextField()
    stub = models.TextField('Заготовка', blank = True) 

    def __unicode__(self):
        return '#' + str(self.id) + ". " + self.title

class MySubmitForm(Form):
    code = CharField(label="Текст программы:", widget=Textarea(attrs={'cols': '120', 'rows': 10}))
    problem = IntegerField(widget=HiddenInput())       

TYPE_CHOICES = (
    (3, 'проверка данной задачи не осуществляется'),
    (2, 'решение неправильное'),
    (1, 'решение верное')
)



class MySubmit(models.Model):
    code = models.TextField()
    time = models.DateTimeField(default=datetime.now)
    verdict = models.IntegerField(choices=TYPE_CHOICES)    
    problem = models.ForeignKey(Problem)
    author = models.ForeignKey(User)

    def __unicode__(self):
        return '#' + str(self.id) + ". Problem " + str(self.problem.title) + ": " + str(self.verdict)

class Result(models.Model): #only once solved problems
    user = models.ForeignKey(User)
    problem = models.ForeignKey(Problem)
    score = models.IntegerField('Результат', blank = True)

    def __unicode__(self):
        #FIXME add user lastname and firstname
        return self.user.username + ": " + self.problem.title